<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ObjectStore Allocation Tests</title>

<script type="text/javascript" src="../lib/jsunit/app/jsUnitCore.js"></script>

<script type="text/javascript" src="../lib/prototype/prototype.js"></script>
<script type="text/javascript" src="../lib/gears/gears_init.js"></script>
<script type="text/javascript" src="../src/ObjectThought.js"></script>

<script type="text/javascript" src="testclasses.js"></script>

<script type="text/javascript">//<![CDATA[

var store = null;
var classesToAllocate = [SimpleClass];

function setUp()
{
    console.log("**** enter setUp");
    
    store = ObjectStore.getStore("objectthought_unittests");
    assertNotNull(store);
    
    var allocator = store.getAllocator();
    allocator.deallocate(classesToAllocate);
    
    assertFalse(store.allocatedFor(classesToAllocate));
    
    console.log("**** leave setUp");
}

function testThatWeCanImplicitlyAllocateAStore()
{
    console.log("**** enter testThatWeCanImplicitlyAllocateAStore");

    var simpleObject = new SimpleClass("A Value");
    var validationReport = store.saveObject(simpleObject);
    
    assertTrue(validationReport.toString(), validationReport.passes());
    
    assertTrue(store.allocatedFor(SimpleClass));
    
    console.log("**** leave testThatWeCanImplicitlyAllocateAStore");
}

function testThatTheAllocatorCreationMethodsExist()
{
    console.log("**** enter testThatTheAllocatorCreationMethodsExist");
    
    assertNotUndefined(store.getAllocator);
    assertNotNull(store.getAllocator);
    
    console.log("**** leave testThatTheAllocatorCreationMethodsExist");
}

function testThatWeCanExplicitlyAllocateAStore()
{
    console.log("**** enter testThatWeCanExplicitlyAllocateAStore");
    
    var allocator = store.getAllocator();
    
    allocator.allocate(classesToAllocate);
    
    assertTrue(store.allocatedFor(classesToAllocate));
    classesToAllocate.each(function(classToAllocate)
    {
        assertTrue(store.allocatedFor(classToAllocate))
    });
    
    console.log("**** leave testThatWeCanExplicitlyAllocateAStore");
}

function debugRunThemAll()
{
    setUp();
    testThatWeCanImplicitlyAllocateAStore();
    
    setUp();
    testThatTheAllocatorCreationMethodsExist();
    
    setUp();
    testThatWeCanExplicitlyAllocateAStore();
}

//]]></script>

</head>

<body>
    <p>This is a <a href="http://www.jsunit.net/">JsUnit</a> test page.</p>
    <p>In order to run these tests, please load this html file in JsUnit's <a href="../lib/jsunit/testRunner.html">testRunner.html</a>.</p>
</body>

</html>